import requests
import datetime
from lxml import etree
import json
# 599-获取当天的详细信息 - 代码参考（根据实际业务情况修改）


class tianqi:
        def __init__(self):
            self.req = None
            self.html = None
            self.url ='https://forecast.weather.com.cn/town/weather1dn/101120508007.shtml'  # 接口请求URL
            self.header={
                            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
                            'Accept-Encoding': 'gzip, deflate, sdch',
                            'Accept-Language': 'zh-CN,zh;q=0.8',
                            'Connection': 'keep-alive',
                            'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.235'
                            }# 基本参数配置

        def get_html(self):
            self.req = requests.get(self.url, headers=self.header)
            self.req.encoding='utf-8'
            self.html = etree.HTML(self.req.text)
            return self.html
        def tem(self):
            #温度
            tem = self.html.xpath("//div[@class='tempDiv']/span[@class='temp']/text()")
            print(tem[0])
            return tem[0]
        def hum(self):
            hum = self.html.xpath("//div[@class='todayLeft']/p/span/text()")
            print(hum[1])
            return hum[1]
        def min_tem(self):
            # min tem
            min_tem = self.html.xpath("//div[@id='minTempDiv']/span/text()")
            print(min_tem[0])
            return min_tem[0]
        def max_tem(self):
            max_tem = self.html.xpath("//div[@id='maxTempDiv']/span/text()")
            print(max_tem[0])
            return max_tem[0]

#更新节假日“json/节假日.json”
def updata_rili():
    APIKEY = 'b8eb4e41b5e444da9424b54f5c0a106f'
    url = f"https://apis.tianapi.com/jiejiari/index?key={APIKEY}&date={datetime.datetime.now().year}-{datetime.datetime.now().month}-01&type=2"
    req=requests.get(url)
    dict_data=json.loads(req.text)
    with open('json/节假日.json', 'w') as json_file:
        json.dump(dict_data, json_file)
    print(dict_data)


#更新datetime.json
def updata_datetime():
    with open('json/节假日.json', 'r') as source_file:
        source_data = json.load(source_file)#加载节假日文件
    solar_terms = [
        "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨",
        "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑",
        "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"
    ]




    extracted_data = {
        'ver' : f"{datetime.datetime.now().year}-{datetime.datetime.now().month}-01",
        'list':{}

    }



    # 将提取的参数保存到另一个JSON文件
    with open('json/datetims.json', 'w') as extracted_file:
        json.dump(dict_keys, extracted_file)



if __name__ == '__main__':
    updata_datetime()







